home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / gximage.h < prev    next >
C/C++ Source or Header  |  1993-05-13  |  6KB  |  163 lines

  1. /* Copyright (C) 1989, 1990, 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gximage.h */
  20. /* Internal definitions for image rendering */
  21. /* Requires gxcpath.h, gxdevmem.h, gzcolor.h, gzpath.h */
  22. #include "gscspace.h"
  23. #include "gsimage.h"
  24.  
  25. /* Interface for routine used to unpack and shuffle incoming samples. */
  26. /* The Unix C compiler can't handle typedefs for procedure */
  27. /* (as opposed to pointer-to-procedure) types, */
  28. /* so we have to do it with macros instead. */
  29. #define iunpack_proc(proc)\
  30.   void proc(P6(const gs_image_enum *, sample_map *, byte *, const byte *, uint, uint))
  31. /* Interface for routine used to render a (source) scan line. */
  32. #define irender_proc(proc)\
  33.   int proc(P4(gs_image_enum *, byte *, uint, int))
  34.  
  35. /*
  36.  * Incoming samples may go through two different transformations:
  37.  *
  38.  *    - N-to-8-bit expansion may involve a lookup map.  Currently this
  39.  *    map is either an identity function or a subtraction from 1
  40.  *    (inversion).
  41.  *
  42.  *    - The 8-bit sample may undergo decoding (a linear transformation)
  43.  *    before being handed off to the color mapping machinery.
  44.  *
  45.  * If the decoding function's range is [0..1], we fold it into the
  46.  * expansion lookup; otherwise we must compute it separately.
  47.  * For speed, we distinguish 3 different cases of the decoding step:
  48.  */
  49. typedef enum {
  50.     sd_none,        /* decoded during expansion */
  51.     sd_lookup,        /* use lookup_decode table */
  52.     sd_compute        /* compute using base and factor */
  53. } sample_decoding;
  54. typedef struct sample_map_s {
  55.  
  56.     /* The following union implements the expansion of sample */
  57.     /* values from N bits to 8, and a possible inversion. */
  58.  
  59.     union {
  60.  
  61.         ulong lookup4x1to32[16];    /* 1 bit/sample */
  62.         ushort lookup2x2to16[16];    /* 2 bits/sample */
  63.         /* lookup8 is also used for 1 or 2 bits/sample */
  64.         /* if we are spreading out the samples. */
  65.         byte lookup8[256];        /* 4 bits/sample [16] */
  66.                         /* 8 or 12 bits/sample */
  67.  
  68.     } table;
  69.  
  70.     /* If an 8-bit fraction doesn't represent the decoded value */
  71.     /* accurately enough, but the samples have 4 bits or fewer, */
  72.     /* we precompute the decoded values into a table. */
  73.     /* Different entries are used depending on bits/sample: */
  74.     /*    1,8,12 bits/sample: 0,15    */
  75.     /*    2 bits/sample: 0,5,10,15    */
  76.     /*    4 bits/sample: all    */
  77.  
  78.     float decode_lookup[16];
  79. #define decode_base decode_lookup[0]
  80. #define decode_max decode_lookup[15]
  81.  
  82.     /* In the worst case, we have to do the decoding on the fly. */
  83.     /* The value is base + sample * factor, where the sample is */
  84.     /* an 8-bit (unsigned) integer. */
  85.  
  86.     float decode_factor;
  87.  
  88.     sample_decoding decoding;
  89.  
  90. } sample_map;
  91.  
  92. /* Decode an 8-bit sample into a floating point color component. */
  93. /* penum points to the gs_image_enum structure. */
  94. #define decode_sample(sample_value, cc, i)\
  95.   switch ( penum->map[i].decoding )\
  96.   {\
  97.   case sd_none:\
  98.     cc.paint.values[i] = (sample_value) * (1.0 / 255.0);  /* faster than / */\
  99.     break;\
  100.   case sd_lookup:    /* <= 4 significant bits */\
  101.     cc.paint.values[i] =\
  102.       penum->map[i].decode_lookup[(sample_value) >> 4];\
  103.     break;\
  104.   case sd_compute:\
  105.     cc.paint.values[i] =\
  106.       penum->map[i].decode_base + (sample_value) * penum->map[i].decode_factor;\
  107.   }
  108.  
  109. /* Main state structure */
  110. struct gs_image_enum_s {
  111.     /* We really want the map structure to be long-aligned, */
  112.     /* so we choose shorter types for some flags. */
  113.     /* Following are set at structure initialization */
  114.     int width;
  115.     int height;
  116.     int bps;            /* bits per sample: 1, 2, 4, 8, 12 */
  117.     int spp;            /* samples per pixel: 1, 3, or 4 */
  118.     int spread;            /* spp if colors are separated, */
  119.                     /* 1 otherwise */
  120.     int masked;            /* 0 = [color]image, 1 = imagemask */
  121.     fixed fxx, fxy, fyx, fyy;    /* fixed version of matrix */
  122.     iunpack_proc((*unpack));
  123.     irender_proc((*render));
  124.     gs_state *pgs;
  125.     gs_fixed_rect clip_box;        /* pgs->clip_path.path->bbox, */
  126.                     /* possibly translated */
  127.     byte *buffer;            /* for expanding to 8 bits/sample */
  128.     uint buffer_size;
  129.     byte *line;            /* buffer for an output scan line */
  130.     uint line_size;
  131.     uint line_width;        /* width of line in device pixels */
  132.     uint bytes_per_row;        /* # of input bytes per row */
  133.                     /* (per plane, if spp == 1 and */
  134.                     /* spread > 1) */
  135.     byte never_clip;        /* true if entire image fits */
  136.     byte skewed;            /* true if image is skewed */
  137.                     /* or rotated */
  138.     byte slow_loop;            /* true if !(skewed | */
  139.                     /* imagemask with a halftone) */
  140.     byte device_color;        /* true if device color space and */
  141.                     /* standard decoding */
  142.     fixed adjust;            /* adjustment when rendering */
  143.                     /* characters */
  144.     gx_device_clip clip_dev;    /* clipping device (if needed) */
  145.     /* Following are updated dynamically */
  146.     byte *planes[4];        /* separated color data */
  147.     int plane_index;        /* current plane index, [0..spp) */
  148.     uint plane_size;        /* size of data in each plane */
  149.     uint byte_in_row;        /* current input byte position in row */
  150.     fixed xcur, ycur;        /* device x, y of current row */
  151.     int yci, hci;            /* integer y & height of row */
  152.                     /* (if no skew) */
  153.     int y;
  154.     /* The maps are set at initialization.  We put them here */
  155.     /* so that the scalars will have smaller offsets. */
  156.     sample_map map[4];
  157.     /* Entries 0 and 255 of the following are set at initialization */
  158.     /* for monochrome images; other entries are updated dynamically. */
  159.     gx_device_color dev_colors[256];
  160. #define icolor0 dev_colors[0]
  161. #define icolor1 dev_colors[255]
  162. };
  163.